package com.vhans.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.vhans.core.domain.Image;
import com.vhans.db.service.IImageService;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.image.ImageDTO;
import com.vhans.db.model.vo.image.*;
import com.vhans.core.web.page.TableDataInfo;

import java.util.List;

/**
 * 镜像Controller控制器
 * 
 * @author vhans
 * @date 2023-05-20
 */
@Api(tags = "镜像模块")
@RestController
@RequestMapping("/dome/image")
public class ImageController extends BaseController {
    @Autowired
    private IImageService imageService;

    /**
     * 查询镜像列表
     * @param condition 条件
     * @return {@link ImageVO} 题目列表
     */
    @ApiOperation(value = "查询镜像列表")
    @SaCheckPermission("dome:image:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<ImageVO> list = imageService.selectImageVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取镜像详细信息
     * @param id 镜像id
     * @return {@link Result<ImageInfoVO>} 镜像信息
     */
    @ApiOperation(value = "获取镜像编辑信息")
    @SaCheckPermission("dome:image:query")
    @GetMapping(value = "/info/{id}")
    public Result<ImageInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(imageService.selectImageInfoById(id));
    }

    /**
     * 新增镜像
     *
     * @param image 镜像信息
     * @return {@link Result<>}
     */
    @ApiOperation(value = "新增镜像")
    @SaCheckPermission("dome:image:add")
    @PostMapping("/add")
    public Result<Integer> add(@Validated @RequestBody ImageDTO image) {
        Integer id = imageService.insertImage(image);
        return Result.success(id);
    }

    /**
     * 修改镜像
     */
    @ApiOperation(value = "修改镜像")
    @SaCheckPermission("dome:image:update")
    @PutMapping("/updata")
    public Result<?> update(@Validated @RequestBody ImageDTO image) {
        return toAjax(imageService.updateImage(image));
    }

    /**
     * 删除镜像
     *
     * @param idList 需要删除的镜像主键列表
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除镜像")
    @SaCheckPermission("dome:image:delete")
	@DeleteMapping("/delete")
    public Result<?> delete(@RequestBody List<Integer> idList) {
        return toAjax(imageService.deleteImageByIdIdList(idList));
    }
}
